using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FrameWork.Source.FrameWork;
using FrameWork.Source.Texture;
using FrameWork.Source.Resource_Manager;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.GamerServices;
using FrameWork.Source.Global_variables;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace FrameWork.Source.Screen
{
    class SplashScreen : IGameState
    {
        VideoPlayer videoPlayer;
        Video video;
        Texture2D videoTexture;

        public SplashScreen(StateManager pState)
            : base(pState)
        {

        }


        public override void init()
        {
            video = this.m_pState.m_pGame.Content.Load<Video>("OtherRes//Comp 1_1");

            videoPlayer = new VideoPlayer();

            videoPlayer.Play(video);
            videoPlayer.IsLooped = false;
            base.init();
        }

        public override void update(GameTime gameTime)
        {
            if (videoPlayer.State == MediaState.Stopped)
            {
                m_pState.setNextState(new MainMenuState(m_pState));
            }

            base.update(gameTime);
        }

        public override void render(GameTime gameTime)
        {
            // Only call GetTexture if a video is playing or paused
            if (videoPlayer.State != MediaState.Stopped)
                videoTexture = videoPlayer.GetTexture();

            // Drawing to the rectangle will stretch the 
            // video to fill the screen
            Rectangle screen = new Rectangle(this.m_pState.m_pGame.GraphicsDevice.Viewport.X,
                this.m_pState.m_pGame.GraphicsDevice.Viewport.Y,
                this.m_pState.m_pGame.GraphicsDevice.Viewport.Width,
                this.m_pState.m_pGame.GraphicsDevice.Viewport.Height);

            // Draw the video, if we have a texture to draw.
            if (videoTexture != null)
            {
                this.m_pState.m_pSpriteHandler.Begin();
                this.m_pState.m_pSpriteHandler.Draw(videoTexture, screen, Color.White);
                this.m_pState.m_pSpriteHandler.End();
            }

            base.render(gameTime);
        }

        public override void destroy()
        {
            base.destroy();
        }
    }
}
